﻿@{
    ViewBag.Title = "违章管理信息";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="../Scripts/jquery.AnkeExtend.js"> </script>
    <script type="text/javascript">
        //页面动态改动
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridViolation");
        });

        //页面初始化
        $(document).ready(function () {

            initListcombo();
            initcombo();
            bindGrid();
            initPassGrid();
            DisableBackspace();
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridViolation");
        })
        //#region 为Combobox增加--请选择--
        function EUIcombobox(jqS, o) {
            $.ajax({
                type: "POST",
                async: false,
                url: o.url,
                dataType: "JSON",
                success: function (data1, textStatus, jqXHR) {
                    o.data = o.OneOption.concat(data1);
                    delete o.url;
                    delete o.OneOption;
                    $(jqS).combobox(o);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("获取字典数据失败！可能是已经超时，请重新登录！");
                }
            });
        }
        function initListcombo() {
            @*// 分中心分站联动
            $.EUIcombobox("#centerID", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    $.EUIcombobox("#stationID", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }],
                        editable: false
                    });
                }
            });
            //取车牌号码（所有的）
            $.EUIcombobox("#actualCode", {
                url: '@Url.Content("~/CM/Refuel/GetAllActualCode/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取车辆编号（所有的）
            $.EUIcombobox("#ambulanceNumber", {
                url: '@Url.Content("~/CM/Refuel/GetAllAmbulanceNumber/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });*@
            EUIcombobox("#centerID", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    EUIcombobox("#stationID", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',
                        //prompt: '--请选择--',
                        editable: false,
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }]
                    });
                }
            });
            //#endregion

            //#region 出车分站
            EUIcombobox("#stationID", {
                url: '@Url.Content("~/Medical/GetStation?code=")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var zz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                    EUIcombobox("#actualCode", {
                        url: zz,
                        valueField: 'AmbulanceCode',
                        textField: 'PlateNumber',
                        editable: false,
                        OneOption: [{
                            AmbulanceCode: "",
                            PlateNumber: "--请选择--"
                        }]
                    });
                    var zzz = '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")' + rec.ID;
                    EUIcombobox("#ambulanceNumber", {
                        url: zzz,
                        valueField: 'AmbulanceCode',
                        textField: 'CarNumber',
                        editable: false,
                        OneOption: [{
                            AmbulanceCode: "",
                            CarNumber: "--请选择--"
                        }]
                    });
                },
                onChange: function (newValue, oldValue) {
                    $("#ambulanceNumber").combobox('clear');
                    $("#actualCode").combobox('clear');
                }
            });

            //车辆牌号 初始化
            EUIcombobox("#actualCode", {
                url: '@Url.Content("~/CM/CarBasicInfo/getPlateByStationID?stationCode=")',
                valueField: 'AmbulanceCode',
                textField: 'PlateNumber',
                editable: true,
                OneOption: [{
                    AmbulanceCode: "",
                    PlateNumber: "--请选择--"
                }],
                onSelect: function (rec) {

                    $("#ambulanceNumber").combobox('setValue', rec.AmbulanceCode);  //根据选择车牌对应的ID ，给车辆编号赋值
                }
            });
            EUIcombobox("#ambulanceNumber", {       //选择车辆编号的联动 初始化
                url: '@Url.Content("~/CM/CarBasicInfo/getCarNumberByID?ID=")',
                valueField: 'AmbulanceCode',
                textField: 'CarNumber',
                editable: true,
                OneOption: [{
                    AmbulanceCode: "",
                    CarNumber: "--请选择--"
                }],
                onSelect: function (rec) {

                    $("#actualCode").combobox('setValue', rec.AmbulanceCode);  //根据选择车辆编号对应的ID，给车牌号赋值 初始化
                }
            });
            //司机工号和姓名联动
            $.EUIcombobox('#driverWorkID', {
                // prompt: '--请选择--',
                url: '@Url.Content("~/CM/CardInfo/GetDriverWorkID?em=")' + '@ViewData["em"]' + '&selfCenterID=' + '@ViewData["selfCenterID"]' + '&selfStationID=' + '@ViewData["selfStationID"]' + '&selfWorkCode=' + '@ViewData["selfWorkCode"]',//ajax后台取数据路径，返回的是json格式的数据
                valueField: 'ID',
                textField: 'Name',
                method: 'POST',
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/CM/CardInfo/GetListByWorkID")',
                        data:
                            {
                                workID: rec.Name
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $('#driverName').combobox("setText", jsData.model.DriverName);
                        }
                    });
                },
                onChange: function () {
                    $('#driverName').combobox('clear');
                }
            });
            @*//取司机工号
            $.EUIcombobox("#driverWorkID", {
                url: '@Url.Content("~/CM/CardInfo/GetDriverWorkID/")',
                valueField: 'ID',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });*@
            //取司机姓名
            $.EUIcombobox("#driverName", {
                url: '@Url.Content("~/CM/CardInfo/GetDriverNames/")',
                valueField: 'ID',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            $('#start').datebox('setValue', '@ViewData["start"]');
            $('#end').datebox('setValue', '@ViewData["end"]');

        }
        function initPassGrid() {
            if ('@ViewData["txtPlateNumber"]' != null && '@ViewData["txtPlateNumber"]' != "" && '@ViewData["txtPlateNumber"]' != "--请选择--") {
                $('#centerID').combobox('disable');
                $('#stationID').combobox('disable');
                $('#actualCode').combobox('disable');
                $('#ambulanceNumber').combobox('disable');
                $('#centerID').combobox('setValue', '@ViewData["txtCenterCode"]');
                $('#stationID').combobox('setValue', '@ViewData["txtStationCode"]');
                $('#actualCode').combobox('setText', '@ViewData["txtPlateNumber"]');
                $('#ambulanceNumber').combobox('setText', '@ViewData["txtCarNumber"]');
                reSearch();
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
                $('div.datagrid-toolbar div').eq(1).hide();
                $('div.datagrid-toolbar a').eq(1).hide();

            }

        }


        function bindGrid() {
            $('#gridViolation').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: true,
                url: '@Url.Content("~/CM/Violation/DataLoad")',
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页
                rownumbers: true,//显示页码
                pageSize: 15,//设置 页容量
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    start: $('#start').datebox('getValue'),
                    end: $('#end').datebox('getValue'),
                    center: $("#centerID").combobox('getValue'),
                    station: $('#stationID').combobox('getValue'),
                    actualCode: $('#actualCode').combobox('getText'),
                    ambulanceNumber: $('#ambulanceNumber').combobox('getText'),
                    place: $('#place').textbox('getText'),
                    driverName: $('#driverName').combobox('getText'),
                    driverWorkID: $('#driverWorkID').combobox('getText')
                },
                columns: [[
                   { title: 'ID', field: 'ID', width: '8%', align: "center", sortable: false, hidden: true },
                   { title: '分中心编码', field: 'CenterID', width: '7%', align: "center", sortable: false, hidden: true },
                   { title: '分站编码', field: 'StationID', width: '8%', align: "center", sortable: false, hidden: true },
                   { title: '分中心', field: 'Center', width: '7%', align: "center", sortable: false },
                   { title: '分站', field: 'Station', width: '8%', align: "center", sortable: false },
                   { title: '车辆编码', field: 'AmbulanceCode', width: '8%', align: "center", sortable: false, hidden: true },
                   { title: '车牌号码', field: 'ActualCode', width: '9%', align: "center", sortable: false },
                   { title: '车辆编号', field: 'AmbulanceNumber', width: '9%', align: "center", sortable: false },
                   { title: '责任司机工号', field: 'DriverWorkID', width: '8%', align: "center", sortable: false },
                   { title: '责任司机姓名', field: 'DriverName', width: '8%', align: "center", sortable: false },
                   { title: '违章地点', field: 'ViolationPlace', width: '20%', align: "center", sortable: false },
                   { title: '违章内容', field: 'ViolationContent', width: '19%', align: "center", sortable: false },
                   { title: '违章日期', field: 'ViolationTime', width: '11%', align: "center", sortable: false },
                   { title: '处理结果', field: 'DisposeResult', width: '15%', align: "center", sortable: false, hidden: true },
                   { title: '处理日期', field: 'DisposeTime', width: '10%', align: "center", sortable: false, hidden: true },
                   { title: '备注', field: 'Remark', width: '12%', align: "center", sortable: false, hidden: true }
                ]],
                toolbar: [
                    {
                        id: 'btnAdd',
                        text: '新增',
                        iconCls: 'icon-add',
                        handler: function () {
                            $('#NewViolationList').dialog('open');
                            initAddInfo();
                        }
                    }, '-',
                   {
                       id: 'btnEdit',
                       text: '修改',
                       iconCls: 'icon-edit',
                       handler: function () {
                           var row = $('#gridViolation').datagrid('getSelected');
                           if (row) {
                               initUpdateInfo(row);
                               $("#ID").val(row.ID);
                               $("#AmbulanceNumber").combobox("setText", row.AmbulanceNumber);
                               $("#ActualCode").combobox("setText", row.ActualCode);
                               $("#AmbulanceCode").val(row.AmbulanceCode);
                               $("#Center").val(row.CenterID);
                               $("#Station").val(row.StationID);
                               //$("#Center").combobox("setText", row.Center);
                               //$("#Station").combobox("setText", row.Station);
                               $("#ViolationTime").datebox("setValue", row.ViolationTime);
                               $("#ViolationPlace").textbox("setText", row.ViolationPlace);
                               $("#ViolationContent").textbox("setText", row.ViolationContent);
                               $("#DriverWorkID").combobox("setText", row.DriverWorkID);
                               $("#DriverName").combobox("setText", row.DriverName);
                               $("#DisposeResult").textbox("setText", row.DisposeResult);
                               $("#DisposeTime").datebox("setValue", row.DisposeTime);
                               $("#Remark").textbox("setText", row.Remark);

                               $('#NewViolationList').dialog('open');
                           } else {
                               $.messager.alert('提示', '请选择数据行', 'info', function () {
                               });
                           }
                       }
                   }, '-',
                     {
                         id: 'btnSearch',
                         text: '查看',
                         iconCls: 'icon-search',
                         handler: function () {
                             var row = $('#gridViolation').datagrid('getSelected');
                             if (row) {
                                 $("#ID").val(row.ID);
                                 //$("#Center").combobox("setText", row.Center);
                                 //$("#Station").combobox("setText", row.Station);
                                 $("#AmbulanceNumber").combobox("setText", row.AmbulanceNumber);
                                 $("#ActualCode").combobox("setText", row.ActualCode);
                                 $("#AmbulanceCode").val(row.AmbulanceCode);
                                 $("#Center").val(row.CenterID);
                                 $("#Station").val(row.StationID);
                                 $("#ViolationTime").datebox("setValue", row.ViolationTime);
                                 $("#ViolationPlace").textbox("setText", row.ViolationPlace);
                                 $("#ViolationContent").textbox("setText", row.ViolationContent);
                                 $("#DriverWorkID").combobox("setText", row.DriverWorkID);
                                 $("#DriverName").combobox("setText", row.DriverName);
                                 $("#DisposeResult").textbox("setText", row.DisposeResult);
                                 $("#DisposeTime").datebox("setValue", row.DisposeTime);
                                 $("#Remark").textbox("setText", row.Remark);
                                 $('#NewViolationList').dialog('open');
                                 $('#btnadd').linkbutton('disable');
                                 $.GID("btnadd").style.display = "none";
                                 $('#btnedit').linkbutton('disable');
                                 $.GID("btnedit").style.display = "none";
                             } else {
                                 $.messager.alert('提示', '请选择数据行', 'info', function () {
                                 });
                             }
                         }
                     }
                ]
            })
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridViolation");
            if ('@ViewData["em"]' == 'ALL') {
                if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                    $('div.datagrid-toolbar a').eq(0).show();
                    $('div.datagrid-toolbar div').eq(0).show();
                    $('div.datagrid-toolbar div').eq(1).show();
                    $('div.datagrid-toolbar a').eq(1).show();
                    $('div.datagrid-toolbar div').eq(2).show();
                    $('div.datagrid-toolbar a').eq(2).show();
                } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();
                    $('div.datagrid-toolbar div').eq(2).hide();
                    $('div.datagrid-toolbar a').eq(2).hide();
                }
            } else if ('@ViewData["em"]' == 'CENTER') {
                if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                    $('div.datagrid-toolbar a').eq(0).show();
                    $('div.datagrid-toolbar div').eq(0).show();
                    $('div.datagrid-toolbar a').eq(1).show();
                    $('div.datagrid-toolbar div').eq(1).show();
                    $('div.datagrid-toolbar div').eq(2).show();
                    $('div.datagrid-toolbar a').eq(2).show();
                } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();
                    $('div.datagrid-toolbar div').eq(2).hide();
                    $('div.datagrid-toolbar a').eq(2).hide();
                }
            } else if ('@ViewData["em"]' == 'STATION') {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
                $('div.datagrid-toolbar div').eq(1).hide();
                $('div.datagrid-toolbar a').eq(1).hide();
                $('div.datagrid-toolbar div').eq(2).hide();
                $('div.datagrid-toolbar a').eq(2).hide();
            } else if ('@ViewData["em"]' == 'SELF') {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
                $('div.datagrid-toolbar div').eq(1).hide();
                $('div.datagrid-toolbar a').eq(1).hide();
                $('div.datagrid-toolbar div').eq(2).hide();
                $('div.datagrid-toolbar a').eq(2).hide();
            }
        }
        //查询
        function reSearch() {
            $('#gridViolation').datagrid({
                pageNumber: 1,
                queryParams: {
                    start: $('#start').datebox('getValue'),
                    end: $('#end').datebox('getValue'),
                    center: $("#centerID").combobox('getValue'),
                    station: $('#stationID').combobox('getValue'),
                    actualCode: $('#actualCode').combobox('getText'),
                    ambulanceNumber: $('#ambulanceNumber').combobox('getText'),
                    place: $('#place').textbox('getText'),
                    driverName: $('#driverName').combobox('getText'),
                    driverWorkID: $('#driverWorkID').combobox('getText')
                }
            });
            //判断是从车辆基础信息页面点击进入违章页面，还是直接点击违章页面，来显示和隐藏按钮功能
            if ('@ViewData["txtCenterCode"]' == '') {
                if ('@ViewData["em"]' == 'ALL') {
                    if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                        $('div.datagrid-toolbar a').eq(0).show();
                        $('div.datagrid-toolbar div').eq(0).show();
                        $('div.datagrid-toolbar div').eq(1).show();
                        $('div.datagrid-toolbar a').eq(1).show();
                        $('div.datagrid-toolbar div').eq(2).show();
                        $('div.datagrid-toolbar a').eq(2).show();
                    } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                        $('div.datagrid-toolbar a').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(1).hide();
                        $('div.datagrid-toolbar a').eq(1).hide();
                        $('div.datagrid-toolbar div').eq(2).hide();
                        $('div.datagrid-toolbar a').eq(2).hide();
                    }
                } else if ('@ViewData["em"]' == 'CENTER') {
                    if ('@ViewData["RolePermissionInsert"]' == "Insert") {
                        $('div.datagrid-toolbar a').eq(0).show();
                        $('div.datagrid-toolbar div').eq(0).show();
                        $('div.datagrid-toolbar a').eq(1).show();
                        $('div.datagrid-toolbar div').eq(1).show();
                        $('div.datagrid-toolbar div').eq(2).show();
                        $('div.datagrid-toolbar a').eq(2).show();
                    } else if ('@ViewData["RolePermissionInsert"]' != "Insert") {
                        $('div.datagrid-toolbar a').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(0).hide();
                        $('div.datagrid-toolbar div').eq(1).hide();
                        $('div.datagrid-toolbar a').eq(1).hide();
                        $('div.datagrid-toolbar div').eq(2).hide();
                        $('div.datagrid-toolbar a').eq(2).hide();
                    }
                } else if ('@ViewData["em"]' == 'STATION') {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();
                    $('div.datagrid-toolbar div').eq(2).hide();
                    $('div.datagrid-toolbar a').eq(2).hide();
                } else if ('@ViewData["em"]' == 'SELF') {
                    $('div.datagrid-toolbar a').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(0).hide();
                    $('div.datagrid-toolbar div').eq(1).hide();
                    $('div.datagrid-toolbar a').eq(1).hide();
                    $('div.datagrid-toolbar div').eq(2).hide();
                    $('div.datagrid-toolbar a').eq(2).hide();
                }
            } else if ('@ViewData["txtCenterCode"]' != '') {
                $('div.datagrid-toolbar a').eq(0).hide();
                $('div.datagrid-toolbar div').eq(0).hide();
                $('div.datagrid-toolbar div').eq(1).hide();
                $('div.datagrid-toolbar a').eq(1).hide();
            }

        }
    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'违章管理信息',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">违章时间：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="start" class="easyui-datebox" value=@ViewData["start"] style="width:150px" data-options="editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">至：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="end" class="easyui-datebox" value=@ViewData["end"] style="width:150px" data-options="editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">司机工号：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="driverWorkID" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="8%">司机姓名：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="driverName" class="easyui-combobox" style="width:150px" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="8%">分中心：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="centerID" class="easyui-combobox" style="width:150px" data-options="panelHeight:'auto', editable:false" />
                    </td>
                    <td align="right" valign="middle" width="8%">分站：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="stationID" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="8%">车牌号码：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="actualCode" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="8%">车辆编号：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="ambulanceNumber" class="easyui-combobox" style="width:150px" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="8%">违章地点：</td>
                    <td align="right" valign="middle" width="12%">
                        <input id="place" class="easyui-textbox" style="width:150px" />
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td align="center" valign="middle" width="11%">
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridViolation"></table>
        </div>
    </div>
</div>

@Html.Partial("~/Areas/CM/Views/Violation/ViolationEdit.cshtml")